package com.company.libraryservice.service;

import com.company.libraryservice.mapper.BorrowRecordMapper;
import com.company.libraryservice.model.BorrowRecord;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 借还记录业务服务
 *
 * @author RoyMa
 * @date 2025-08-12
 */
@Service
public class BorrowRecordService {
  @Autowired private BorrowRecordMapper mapper;

  public void add(Long bookId, String user, String action) {
    BorrowRecord r = new BorrowRecord();
    r.setBookId(bookId);
    r.setUserName(user);
    r.setAction(action);
    mapper.insert(r);
  }

  /**
   * 查询所有借还记录
   *
   * @return 借还记录列表
   */
  public Map<String, Object> records() {
    List<BorrowRecord> records = mapper.selectAll();
    return Map.of("data", records);
  }
}
